package com.phantasy.modules
{
	import com.phantasy.Message;
	import com.phantasy.managers.Dispatch;
	import com.phantasy.net.connection.Connection;

	/**
	 *模块基类 
	 * @author Liseen
	 * 
	 */	
	public class BaseModule
	{
		protected var connect:Connection;
		
		public function BaseModule()
		{
			this.connect = Connection.getInstance();
			this.initListeners();
		}
		
		protected function initListeners():void
		{
			
		}
		/**
		 *添加Socket侦听 
		 * @param type		类型
		 * @param callBack	回调
		 * 
		 */		
		protected function addSocketListener(type:String, callBack:Function):void
		{
			this.connect.addSocketListener(type, callBack);
		}
		/**
		 *移除Socket侦听 
		 * @param type		类型
		 * @param callBack	回调
		 * 
		 */		
		protected function removeSocketListener(type:String, callBack:Function):void
		{
			this.connect.removeSocketListener(type, callBack);
		}
		/**
		 *发送消息 
		 * @param message	消息体
		 * 
		 */		
		protected function sendSocketMessage(message:Message):void
		{
			this.connect.sendMessage(message);
		}
		/**
		 *派发模块类型 
		 * @param type		类型
		 * @param param		参数
		 * 
		 */		
		protected function dispatch(type:String, param:Object=null):void
		{
			Dispatch.dispatch(type, param);
		}
		/**
		 *添加来自模块的消息 
		 * @param type			类型
		 * @param callBack		回调
		 * 
		 */		
		protected function addMessageListener(type:String, callBack:Function):void
		{
			Dispatch.register(type, callBack);
		}
		/**
		 *移除消息侦听 
		 * @param type
		 * @param callBack
		 * 
		 */		
		protected function removeMessageListener(type:String, callBack:Function):void
		{
			Dispatch.remove(type, callBack);
		}
		
		public function dispose():void
		{
		}
	}
}